var webSocket = {};
//创建websockt


//建立连接事件
function WebSokectOnOpen() {
  alert("已经打开连接！");
  webSocket.Send("WebSocketCreate Success!");
};

//监听事件
function WebSocketOnMessage(event) {

  var pMessage = event.data.split(":");
  if (pMessage[0] == "ws" && pMessage.length == 2) {
    var pCardInfostr = pMessage[1].split("|");
    //alert(pCardInfostr.length);
    if (pCardInfostr.length > 1) {
      document.getElementById("txtpCardInfo").value = pCardInfostr[3] + "|" + pCardInfostr[2];
    }
  }

  //监听来自客户端的数据
  //document.getElementById("Text2").value = event.data;
};

function WebSocketOnClose() {
  //监听来自客户端的数据
  alert('和服务器断开连接');
};

export default {
  CreateWebSocket() {
    console.log('开始读卡')
    webSocket = new WebSocket("ws://127.0.0.1:8089");
    webSocket.onopen = WebSokectOnOpen;
    webSocket.onmessage = WebSocketOnMessage;
    webSocket.onclose = WebSocketOnClose;
    console.log('读卡成功')
    console.log(webSocket)
  },
  //读身份证
  ReadIDCard() {
    //发送到服务器(读身份证信息)
    webSocket.send("81");
  }
}